use std::io;
use walkdir::WalkDir;

/// Retrieves a list of available programming languages based on the YAML files in the `lang` directory.
pub fn get_available_languages() -> Result<Vec<String>, io::Error> {
    let mut languages = Vec::new();
    for entry in WalkDir::new("lang") {
        let entry = entry?;
        if entry.file_type().is_file() {
            let path = entry.path();
            if let Some(extension) = path.extension() {
                if extension == "yml" {
                    if let Some(file_stem) = path.file_stem() {
                        if let Some(language) = file_stem.to_str() {
                            languages.push(language.to_string());
                        }
                    }
                }
            }
        }
    }
    Ok(languages)
}